$(document).ready(function() {
	var height1 = $(window).height() - 55;
	$("#main_layout").attr("style", "margin-top: 5px;width:100%;height:" + height1 + "px");
	$("#main_layout").layout("resize", {
		width : "100%",
		height : height1 + "px"
	});
	$("#form_flagStatus").combobox({

		onChange: function (obj,showID) {

			if($(this).combobox("getValue")==1){
				$("#islunbo").css('display','table-row'); 
			}else{
				$("#islunbo").css('display','none'); 
			}
		}

		});
});

$(window).resize(function() {
	var height1 = $(window).height() - 55;
	$("#main_layout").attr("style", "margin-top: 5px;width:100%;height:" + height1 + "px");
	$("#main_layout").layout("resize", {
		width : "100%",
		height : height1 + "px"
	});
});

/**
 * 条件质量控制搜索
 */
function searchStandard(){
	//s_type,  s_field, s_uploader, s_standardName, s_status, s_displayStatus
	$("#standard").datagrid("load",{
		"s_type":$("#search_type").combobox("getValue"),
		"s_field":$("#search_field").combobox("getValue"),
		"s_uploader":$("#search_uploader").textbox("getValue"),
		"s_standardName":$("#search_standardName").textbox("getValue"),
		"s_status":$("#search_statusName").combobox("getValue"),
		"s_displayStatus":$("#search_displayStatus").combobox("getValue"),
	});
}

/**格式化使用状态列，显示参与人数*/
function showUploaderFormatter(value, rec, index){
	var uploader= (rec.htscFlag == 1 && rec.htUploaderName != null && rec.htUploaderName != "")? (rec.htUploaderName+
			"后台上传") : ((rec.uploaderId != null &&rec.uploaderId != "")?"<a style='cursor:pointer;color: #2A2AFF;'  " +
					"  onclick=\"openDialog('"+ rec.uploaderId +"')\">"+rec.uploaderNickName+"</a>":"");
	 return uploader;
}

/**格式化使用状态列，将传入值变成复选框模式*/
function displayStatusFormatter(value, rec, index){
	var img = rec.displayStatus == 1?"icon icon-ok":"icon icon-delete3";
	return "<span class='"+img+"' style='height: 18;'></span>";
}

/**格式化使用状态列，将传入值变成复选框模式*/
function lookPowerFormatter(value, rec, index){
	debugger;
	var returnValue = rec.lookPower?"是":"否";
	return returnValue;
}

/**格式化使用状态列，时间只显示年月日模式*/
function dateHHmmssFormatter(value, rec, index){
	 return value != null?value.replace("T"," "):"";
}

/**格式化使用状态列，将传入值变成<a>标签*/
function pdfFileFormatter(value, rec, index){
	var pdf = (rec.filePath != null && rec.filePath != "")?"<a style='cursor:pointer;color: #2A2AFF;'  target=_blank  href='"+ rec.filePath.substr(1)+"')>"+value+"</a>":"";
	 return pdf;
}

//-----------------------上传者详情Start----------------------------------------------
function openDialog(uploaderId){
	$('#uploader_dialog').dialog({
        title: '上传者详情',
    });
	$('#uploader_dialog').dialog('open');
	$.post("admin/qualityControl/qualityControl_sponsorInfo.action?qualityControl.sponsor.accountId=" + uploaderId,
	        function(data) {
			$('#accountId').text(data.sponsor.accountId != null?data.sponsor.accountId:"");
			$('#nickName').text((data.sponsor.nickName != null?data.sponsor.nickName:"")+
					(data.sponsor.accountTypeName != null?" ("+data.sponsor.accountTypeName+")":""));
			$('#linkMan').text(data.sponsor.linkMan != null?data.sponsor.linkMan:"");
			$('#phone').text(data.sponsor.phone != null?data.sponsor.phone:"");
			$('#fax').text(data.sponsor.fax != null?data.sponsor.fax:"");
			$('#email').text(data.sponsor.email != null?data.sponsor.email:"");
    });
}

function dialog_close (){
	$('#uploader_dialog').dialog('close');
}

//-----------------------上传者详情End----------------------------------------------
//-----------------------按钮详细方法Start----------------------------------------------
function form_standard_init(){
	$("#form_standardId").val("");
	$("#form_standardName").textbox('setValue', "");
	$("#form_type").combobox('setValue', "");
	$("#form_field").combobox('setValue', "");
	$("#form_file").val("");
}

/**
 * 添加资讯详情
 */
function addStandard(){
	
	$('#addAndUpdata_dialog').dialog({
        title: '上传标准',
        iconCls: 'icon-book_addresses_add',
    });
	
	//判断表格是否被选中，如果选中则取消选中
	var item=$('#standard').datagrid('selectRow');
	if(!item==null){
		$("#standard").datagrid("unselectRow", item);
	}
	
	//初始化表单值
	form_standard_init();

	 $('#standard_form').form({
	 url: 'admin/standard/standard_saveOrUpdateStandard.action',
	 onSubmit: function() {
	 return $(this).form('validate');
	 },
	 success: function(data) {
	 var json = JSON.parse(data);
	 if (json.result == "Success") {
	 $('#addAndUpdata_dialog').dialog('close');
	 $.messager.alert('提示', json.message, 'info');
	 $("#standard").datagrid("load");
	 } else {
	 $.messager.alert('错误', json.message, 'error');
	 }
	 }
	    });
    $('#addAndUpdata_dialog').dialog('open');
	
}

/**
 * 批量添加资讯详情
 */
function addStandardBatch(){
	
	$('#addBatch_dialog').dialog({
        title: '批量上传',
        iconCls: 'icon-book_addresses_add',
    });
	
	//判断表格是否被选中，如果选中则取消选中
	var item=$('#standard').datagrid('selectRow');
	if(!item==null){
		$("#standard").datagrid("unselectRow", item);
	}
	
	//初始化表单值
	$("#batch_standardId").val("");
	$("#batch_type").combobox('setValue', "");
	$("#batch_field").combobox('setValue', "");
	$("#batch_file").val("");

	 $('#batch_form').form({
	 url: 'admin/standard/standard_saveBatch.action',
	 onSubmit: function() {
	 return $(this).form('validate');
	 },
	 success: function(data) {
	 var json = JSON.parse(data);
	 if (json.result == "Success") {
	 $('#addBatch_dialog').dialog('close');
	 $.messager.alert('提示', json.message, 'info');
	 $("#standard").datagrid("load");
	 } else {
	 $.messager.alert('错误', json.message, 'error');
	 }
	 }
	    });
    $('#addBatch_dialog').dialog('open');
	
}

/**
 * 修改资讯详情
 */
function updateStandard(){
	
	$('#addAndUpdata_dialog').dialog({
        title: '修改标准',
        iconCls: 'icon-book_addresses_edit',
    });
	
	//判断表格是否被选中，如果选中则取消选中
	var item="";
	try{
		item=$('#standard').datagrid('getSelected');
		}catch (e) {
		}
		
	if(item==""||item==null){
		$.messager.alert('错误', '请选择要修改的详情项！', 'error');
		return;
	}
	form_standard_init();
	//初始化表单值
	$.post("admin/standard/standard_standardModifyInfo.action?standard.standardId=" + item.standardId,
	        function(data) {

			$("#form_standardId").val(data.standard.standardId);
			$("#form_status").val(data.standard.status);
			$("#form_displayStatus").val(data.standard.displayStatus);
	    	$("#form_standardName").textbox('setValue', data.standard.standardName);
	    	$("#form_type").combobox('setValue', data.standard.type);
	    	$("#form_field").combobox('setValue', data.standard.field);
	    });
	
	
    $('#standard_form').form({
        url: 'admin/standard/standard_saveOrUpdateStandard.action',
        onSubmit: function() {
            return $(this).form('validate');
        },
        success: function(data) {
            var json = JSON.parse(data);
            if (json.result == "Success") {
                $('#addAndUpdata_dialog').dialog('close');
                $.messager.alert('提示', json.message, 'info');
    			$("#standard").datagrid("load");
            } else {
                $.messager.alert('错误', json.message, 'error');
            }
        }
    });
    $('#addAndUpdata_dialog').dialog('open');
	
}

function addOrUpdata() {
	$('#standard_form').submit();
}
function addBatch() {
	$('#batch_form').submit();
}


function auditPass() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("尚未选中任何标准！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要通过审核?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_auditPass.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

function auditNoPass() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("尚未选中任何标准！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定改为不通过?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_auditNoPass.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

function show() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("请选择要显示的内容！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要显示?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_show.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

function hide() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("请选择要不显示的内容！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要不显示?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_hide.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

function dataremove() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("请选择要删除的内容！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要删除?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_remove.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

//弹出加载层
function load() {  
    $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");  
    $("<div class=\"datagrid-mask-msg\"></div>").html("正在加载，请稍候。。。").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });  
}  
  
//取消加载层  
function disLoad() {  
    $(".datagrid-mask").remove();  
    $(".datagrid-mask-msg").remove();  
}

//2016.08.14新加功能  未登录可见与隐藏
function noLoginShow() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("请选择要显示的内容！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要显示?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_noLoginShow.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}

function noLoginHide() {
	// 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#standard').datagrid('getSelections');  
    var i = 0;  
    var ids = "";  
    for(i;i<row.length;i++){  
    	ids += row[i].standardId;  
        if(i < row.length-1){  
        	ids += ',';  
        }else{  
            break;  
        }  
    }  
//    alert(string);
    if (row.length== 0) {  
        alert("请选择要不显示的内容！");  
    }  
    if (row.length>0) {  
        $.messager.confirm('操作提示', '确定要隐藏?', function(r) {  
            if (r) { 
            	load();
                $.post('admin/standard/standard_noLoginHide.action?standardIds='+ids, function(data) {  
                	disLoad();
                    if (data.result == "Success") {
                        $.messager.alert('提示', data.message, 'info');
            			$("#standard").datagrid("load");
                    } else {
                        $.messager.alert('错误', data.message, 'error');
                    }  
                });  
            }  
        });  
    }  
}



//-----------------------按钮详细方法End----------------------------------------------